package com.hatricks.as.transformer;

import java.lang.instrument.ClassFileTransformer;
import java.security.ProtectionDomain;
import java.util.regex.Pattern;

public class ExceptionTransformer implements ClassFileTransformer {
    private static final Pattern EXCEPTION_CLASS_PATTERN = Pattern.compile("com.hatricks.AgentTest");

    @Override
    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
        System.out.println("class name的值为:" + className);
        if (EXCEPTION_CLASS_PATTERN.matcher(className).find()) {
            // 仅对 RuntimeException 类进行修改
            return manipulateExceptionClass(classfileBuffer);
        }
        return null; // 不修改其他类
    }

    private byte[] manipulateExceptionClass(byte[] classfileBuffer) {
        // 这里的实现将根据需要修改，这里只是示例，不实际修改字节码
        return classfileBuffer;
    }




}